package com.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class MyHttpServer {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(8899);
        System.out.println("server started on port 8899");
        while (true) {
            try(Socket client = server.accept();
                BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
                PrintWriter out = new PrintWriter(client.getOutputStream());
                ) {
                String requestLine = in.readLine();
                if (requestLine ==null) continue;
                String response = "HTTP/1.1 200 OK\r\n\r\n<h1>Hello from java Server by myself!<p style='color:red'>hifjidfj</p><a href='https://www.baidu.com/'>click me </a></h1>";

                out.println(response);
            }
        }
    }
}
